import axios from 'axios';

// 定义基础指标类型
interface BaseMetrics {
    MAE: number;
    R2: number;
    RMSE: number;
    test_days: number;
}

// 定义单模型评估指标
interface SingleModelMetrics extends BaseMetrics {
    first_date: string;
    last_date: string;
    model_used: string;
}

// 定义评估响应类型
export interface EvaluationResponse {
    metrics: SingleModelMetrics;
    model_type: 'single';
    plot_url: string;
    status: 'success' | 'error';
    message?: string; // 错误时使用
}

// 模型类型枚举
export enum ModelType {
    ENSEMBLE = 'ensemble',
    LSTM = 'lstm'
}

// 目标类型枚举
export enum TargetType {
    GUILIN_MAX = 'guilin_max',
    GUILIN_MIN = 'guilin_min'
}

// 模型评估API服务
export const evaluateModel = async (
    target: TargetType = TargetType.GUILIN_MAX, // 修正默认值为有效枚举成员
    testDays: number = 365,
): Promise<EvaluationResponse> => {
    try {
        const response = await axios.get(
            `http://127.0.0.1:5000/api/evaluate_ensemble`,
            {
                params: {
                    target,
                    test_days: testDays,
                    model_type: 'single' // 固定为单模型
                }
            }
        );
        return response.data;
    } catch (error) {
        console.error('模型评估失败:', error);
        throw {
            status: 'error',
            message: error.response?.data?.message || '请求评估接口失败'
        };
    }
};